import java.io.*;
import java.util.ArrayList;

public class FileHandler {
    private String path;
    private File file;

    public FileHandler(String fileName) {
        path = fileName;
        file = new File(fileName);
    }

    public FileHandler(File file) throws IOException {
        this.file = file;
        path = file.getCanonicalPath();
    }

    public File getFileDescriptor() {
        return file;
    }

    public ArrayList<String> read() {
        try {
            BufferedReader in = new BufferedReader(new FileReader(file));
            ArrayList<String> content = new ArrayList<String>();
            String line;
            while ((line = in.readLine()) != null) {
                content.add(line);
            }
            in.close();
            return content;
        } catch (Exception e) {
            System.out.println("Error file's reading: " + e.getMessage());
            return null;
        }
    }

    public void write(String content) throws IOException {
        BufferedWriter out = new BufferedWriter(new FileWriter(file));
        out.write(content + "\n");
        out.close();
    }

    public void clear() {
        file.delete();
        file = new File(path);
    }
}
